import axios, { AxiosRequestConfig } from 'axios'
import store from '../store'

// interceptors 请求拦截器
axios.interceptors.request.use(config  => {
  store.commit('setLoading',true)  
  return config
})

// interceptors 响应拦截器
axios.interceptors.response.use(res => {
    store.commit('setLoading',false)
    return res
}, e => {
    console.log(e)
    const { error } = e.response.data
    return Promise.reject(error)
})

export { axios, AxiosRequestConfig }